//
//  WLFileBaseCenter.h
//  WanLian
//
//  Created by 123456 on 2018/12/7.
//  Copyright © 2018 wanlian. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "MonitorFlow.h"

NS_ASSUME_NONNULL_BEGIN
@class WLSocketWorker;
@class WLFileUpDownLoadModel;
@protocol WLFileBaseCenterDelegate <NSObject>
- (void)dealWithProcess:(float)progress receivedSize:(NSInteger)receivedSize expectedSize:(NSInteger)expectedSize index:(NSInteger)index;
- (void)updateProgress:(float)progress index:(NSInteger)index;
- (void)didDeleteTaskWithIndexPath:(NSIndexPath *)indexPath;
- (void)didCompleteTaskWithModel:(WLFileUpDownLoadModel *)model;
- (void)didFailTaskWithIndex:(NSInteger)index;
- (void)didStartTastWithIndex:(NSInteger)index;
- (void)willDeleteTaskWithIndexPath:(NSIndexPath *)indexPath;
- (void)updateUI;
- (void)updateNetSpeed:(NSString *)netSpeed withIndex:(NSInteger)index;
@end
@interface WLFileBaseCenter : NSObject

@property (nonatomic, weak) id<WLFileBaseCenterDelegate> delegate;

@property (nonatomic, assign) int sucNum;
//@property (nonatomic, assign) int failNum;
@property (nonatomic, strong) NSMutableArray *totalTaskArray;
@property (nonatomic, strong) NSMutableArray *needUploadArray;
@property (nonatomic, strong) NSMutableArray *uploadedArray;
@property (nonatomic, assign) NSInteger currentTaskIndex;

- (void)addTasks:(NSArray *)tasks;
- (void)deleteTaskWithIndexPath:(NSIndexPath *)indexPath;
- (void)pauseTaskWithIndexPath:(NSIndexPath *)indexPath;
- (void)continueTaskWithIndexPath:(NSIndexPath *)indexPath;
- (WLSocketWorker *)startTaskWithModel:(WLFileUpDownLoadModel *)model;
/** 获取当前队列中所有准备发送中的数组 */
- (NSArray *)getTasksArray;

- (BOOL)isTaskCanBeStart:(WLFileUpDownLoadModel *)model;
- (void)saveInfo;

- (void)dealWithProcess:(float)uploadProgress model:(WLFileUpDownLoadModel *)model;

- (void)dealWithSuccess:(NSDictionary *)successDict model:(WLFileUpDownLoadModel *)model;

- (void)dealWithFailure:(NSString *)errorMsg errorTag:(NSInteger)errorTag  model:(WLFileUpDownLoadModel *)model;
/** 暂停任务 */
- (void)pauseCurrentTask;
/***************** 数据库操作 **************************/
- (void)deleteDataBaseWithModel:(WLFileUpDownLoadModel *)model;
- (void)saveTaskToDataBaseWithModel:(WLFileUpDownLoadModel *)model;

- (NSArray *)queryModelWithFileName:(NSString *)fileName;
- (void)updateTaskToDataBaseWithModel:(WLFileUpDownLoadModel *)model;
- (void)updateTaskToDataBaseWithModel:(WLFileUpDownLoadModel *)model condictionDict:(NSDictionary *)dict;
- (void)updateNetSpeed:(NSString *)netSpeed;

- (void)removeLocalFile:(WLFileUpDownLoadModel *)model;
- (void)startMonitor;
- (void)stopMonitor;
- (WLFileUpDownLoadModel *)getCurrentTask;
- (BOOL)judgeInUploadingWithFileName:(NSString *)fileName;

- (WLFileUpDownLoadModel *)findTaskModelWithName:(NSString *)fileName;
- (WLFileUpDownLoadModel *)findNextModelWithIndex:(NSInteger)index;

- (void)checkShowCompleteAlert:(BOOL)isUpload;
@end

NS_ASSUME_NONNULL_END
